<?php

  require('Wordnik.php'); 
  $api_key = '7b8d5017f3da432ccc1060da2130602daad9519ca0f7358de';
  // create an instance of the Wordnik class, to make api calls
  $wordnik = Wordnik::instance($api_key);
  
  
//$term = strip_tags(substr($_POST['define_term'],0, 100));

$term = strip_tags(substr($_POST['search_term'],0, 100));

$string = '<ul>';
$pronounces = $wordnik->getTextPronunciations($term);
foreach($pronounces as $p)  {
	$string .= '<li>'.$p->raw.'</li>';
  }
$string .= '</ul>';

$definitions = $wordnik->getDefinitions($term);
$string .= '<ul>';
foreach($definitions as $definition) {
	if (isset($definition->text)) {
	  $string .=('<li>'.$definition->text.'</li>');
	}
  }
$string .= '</ul>';


$string .='<ul>';
$phrases = $wordnik->getPhrases($term);
foreach($phrases as $phrase)  {
	$string .= '<li>'.$complete_phrase = ($phrase->gram1 . ' ' . $phrase->gram2).'</li>';
  }
$string .='</ul>';


$examples = $wordnik->getExamples($term);
$string .= '<ul>';
		foreach($examples as $example) {
            if (isset($example->display)) {
              $string .= ('<li>'.$example->display.'</li>');
              if (isset($example->title)) {
                $string .= ('<li><em>'.$example->title.'</em></li>');
              }
            }
          }
$string .= '</ul>';


echo $string;

?>
